//  ==================================================================================
//	This program is written for extract/project standard cosmological parameters onto
//	those derived parameters, such as \sigma_8
//
//	**** NOT FINISHED ****
//  ==================================================================================

#include "ClassMC.hpp"

using namespace std;
using namespace imcmc;
using namespace imcmc::parser;

CosmoTheory theory;
DataList    datalist;

vector<string> mcmc_params;
vector<string> derived_params;



int main( int argc, char* argv[] ){

    MPI::Init(argc, argv);

    int rank = MPI::COMM_WORLD.Get_rank();

    if( (argc < 3) && rank == 0 ){
        cout << "**** on input parameter file found ****\n";
        cout << "usage: " << argv[0] << " param_old.ini param_derived.ini\n";
        MPI::Finalize();
    }

    ensemble_workspace ew;

//  get configuration file:
    string paramfile_old(argv[1]);
    string paramfile_derived(argv[2]);

//  configure datasets.
	datalist.Init(paramfile_old);

//  PLANCK data has a self-check, which needs some time. so we need to make sure
//  all datasets are prperly initilized before we proceeds
    MPI::COMM_WORLD.Barrier();

//  configure cosmological model
    theory.Init(paramfile_old);

//  decide what to calculate and pass cosmological MCMC parameters to datalist.ParList
    theory.Init(datalist);

//	Test part
	// CosmoTheoryTest CTT;
	// CTT.RunTest(paramfile,&theory);
	// exit(0);

    datalist.Get_MCMC_Params(mcmc_params);

    datalist.Get_Derived_Params(derived_params);

	MPI::COMM_WORLD.Barrier();

    ew.add_likelihood(  Likelihoods,
                        mcmc_params,
                        derived_params,
                        &theory,
                        &datalist );

    ew.init(paramfile);

    ew.do_sampling();

    MPI::Finalize();
}

void MPI_cout(string msg, int rank){
    if( rank == ROOT_RANK ){
        cout << "MPI::MSG ==> " << msg << endl;
    }
}
